package org.example;


import static java.util.Collections.reverse;

//反转数组
public class topic189 {
    public void rotate(int[] nums, int k){
        int n = nums.length;
        k %= n;
        reverse(nums,0,n-1);
        reverse(nums, 0,k-1);
        reverse(nums, k, n-1);

    }

    private void reverse(int[] nums, int start, int end) {
        while (start < end) {
            int temp = nums[start];
            nums[start] = nums[end];
            nums[end] = temp;
            start++;
            end--;
        }
    }
}
